package com.mz.ozy.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.activity.MainActivity;
import com.mz.ozy.activity.home.HomeActivity;
import com.mz.ozy.activity.shop.MallActivity;
import com.mz.ozy.activity.shop.ShopDetailActivity;
import com.mz.ozy.activity.shop.SortSearchActivity;
import com.mz.ozy.activity.shop.TopicListActivity;
import com.mz.ozy.bean.HomeMerBean;
import com.mz.ozy.bean.MallBean;
import com.mz.ozy.constants.Constants;
import com.mz.ozy.utils.glideUtils.GlideUtils;
import com.mz.ozy.widget.dialog.NotVipDialog;

import java.util.List;

/**
 * Created by administrator on 2018/11/21.
 */
public class HomeTopicAdapter extends BaseQuickAdapter<HomeMerBean.SpecialListBean, BaseViewHolder> {
    private Activity mActivity;

    public HomeTopicAdapter(Activity activity, @Nullable List<HomeMerBean.SpecialListBean> data) {
        super(R.layout.list_home_food, data);
        this.mActivity=activity;
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeMerBean.SpecialListBean item) {
        RecyclerView rvOrganicFood = helper.getView(R.id.rv_organic_food);
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(mContext);
        layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);//把布局设为横行排列
        rvOrganicFood.setLayoutManager(layoutManager1);
        HomeOrganicAdapter homeOrganicAdapter = new HomeOrganicAdapter(item.getProductList());
        rvOrganicFood.setAdapter(homeOrganicAdapter);
        homeOrganicAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                if (!Constants.isVip) {
//                    NotVipDialog dialog = new NotVipDialog(mActivity);
//                    dialog.showDialog();
//                    return;
//                }
                final HomeMerBean.ProductListBean productListBean = (HomeMerBean.ProductListBean) adapter.getItem(position);
                switch (view.getId()) {
                    case R.id.ll_item_view: {
                        Intent intent = new Intent(mContext, ShopDetailActivity.class);
                        intent.putExtra("goodsId", productListBean.getId() + "");
                        mContext.startActivity(intent);
                        break;
                    }
                    case R.id.iv_goods_pic: {
                        Intent intent = new Intent(mContext, ShopDetailActivity.class);
                        intent.putExtra("goodsId", productListBean.getId() + "");
                        intent.putExtra("show", 1);
                        mContext.startActivity(intent);
                        break;
                    }
                }
            }
        });

        helper.setText(R.id.tv_topic_title, item.getTitle());
        ImageView ivOrganicFood = helper.getView(R.id.iv_organic_food);
        GlideUtils.loadRoundImg(mContext, ivOrganicFood, item.getImgPath(), R.mipmap.bg_organic_food, 4);

        final HomeMerBean.SpecialListBean specialListBean = item;
        ivOrganicFood.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
//                if (!Constants.isVip) {
//                    NotVipDialog dialog = new NotVipDialog(mActivity);
//                    dialog.showDialog();
//                    return;
//                }
                Intent intent = new Intent(mContext, TopicListActivity.class);
                intent.putExtra("id", String.valueOf(specialListBean.getId()));
                intent.putExtra("name", specialListBean.getTitle());
                intent.putExtra("type", "2");
                mContext.startActivity(intent);
            }
        });
        TextView tvOrganicMore = helper.getView(R.id.tv_organic_more);
        tvOrganicMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                if (!Constants.isVip) {
//                    NotVipDialog dialog = new NotVipDialog(mActivity);
//                    dialog.showDialog();
//                    return;
//                }
                Intent intent = new Intent(mContext, TopicListActivity.class);
                intent.putExtra("id", String.valueOf(specialListBean.getId()));
                intent.putExtra("name", specialListBean.getTitle());
                intent.putExtra("type", "2");
                mContext.startActivity(intent);
            }
        });
    }
}
